import storage from 'store'
import { ACCESS_TOKEN, ACCESS_REFRESH_TOKEN, PERMISSIONS, ALLPERMISSIONS, ROLES, USER_INFO } from '@/store/mutation-types'
const getters = {
  roles: state => { // 用户拥有的角色，暂未实现
    state.account.roles || []
    const roles = storage.get(ROLES)
    state.account.roles = new Set(roles && JSON.parse(roles))// 设置为set结构，方便后续判断
    return state.account.roles
  },
  permissions: state => { // 用户拥有的权限标识
    const permissions = storage.get(PERMISSIONS)
    state.account.permissions = new Set(permissions && JSON.parse(permissions))// 设置为set结构，方便后续判断
    return state.account.permissions
  },
  allPermissions: state => { // 系统全部权限标识
    const allPermissions = storage.get(ALLPERMISSIONS)
    state.account.allPermissions = new Set(allPermissions && JSON.parse(allPermissions))// 设置为set结构，方便后续判断
    return state.account.allPermissions
  },
  token: state => {
    const token = storage.get(ACCESS_TOKEN)
    state.account.token = token
    return state.account.token
  },
  refreshToken: state => {
    const token = storage.get(ACCESS_REFRESH_TOKEN)
    state.account.refreshToken = token
    return state.account.refreshToken
  },
  userinfo: state => {
    const userinfo = storage.get(USER_INFO) || {}
    state.account.user = userinfo
    return state.account.user
  }
}
export default getters
